package com.example.coursehub.user.dto;

import com.example.coursehub.user.entity.User;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

/**
 * 用户数据传输对象
 */
public class UserDTO {
    
    private String userId;
    private String userName;
    private String userAccount;
    private Integer status;
    private User.UserRole role;
    private LocalDateTime createdAt;
    private LocalDateTime updatedAt;

    // 无参构造函数
    public UserDTO() {}

    // 全参构造函数
    public UserDTO(String userId, String userName, String userAccount, Integer status, 
                   User.UserRole role, LocalDateTime createdAt, LocalDateTime updatedAt) {
        this.userId = userId;
        this.userName = userName;
        this.userAccount = userAccount;
        this.status = status;
        this.role = role;
        this.createdAt = createdAt;
        this.updatedAt = updatedAt;
    }

    // Getter methods
    public String getUserId() { return userId; }
    public String getUserName() { return userName; }
    public String getUserAccount() { return userAccount; }
    public Integer getStatus() { return status; }
    public User.UserRole getRole() { return role; }
    public LocalDateTime getCreatedAt() { return createdAt; }
    public LocalDateTime getUpdatedAt() { return updatedAt; }

    // Setter methods
    public void setUserId(String userId) { this.userId = userId; }
    public void setUserName(String userName) { this.userName = userName; }
    public void setUserAccount(String userAccount) { this.userAccount = userAccount; }
    public void setStatus(Integer status) { this.status = status; }
    public void setRole(User.UserRole role) { this.role = role; }
    public void setCreatedAt(LocalDateTime createdAt) { this.createdAt = createdAt; }
    public void setUpdatedAt(LocalDateTime updatedAt) { this.updatedAt = updatedAt; }

    /**
     * 从User实体转换为DTO
     */
    public static UserDTO fromEntity(User user) {
        if (user == null) {
            return null;
        }
        return new UserDTO(
            user.getUserId(),
            user.getUserName(),
            user.getUserAccount(),
            user.getStatus(),
            user.getRole(),
            user.getCreatedAt(),
            user.getUpdatedAt()
        );
    }
}